package cn.mimedai.blur;

import android.graphics.drawable.Drawable;
import android.os.Bundle;
import android.support.annotation.Nullable;
import android.support.v7.app.AppCompatActivity;
import android.view.View;
import android.view.ViewGroup;

import cn.mimedai.blurlib.view.BlurView;
import cn.mimedai.blurlib.view.SupportRenderScriptBlur;

/**
 * Created by renjialiang on 2017/7/17.
 */

public class ViewBlurActivity extends AppCompatActivity {

    BlurView mBurView;

    @Override
    protected void onCreate(@Nullable Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_view_blur);

        mBurView = (BlurView) findViewById(R.id.blurView);
        setupBlurView();
    }

    /**
     * 设置毛玻璃.
     */
    private void setupBlurView() {
        final View decorView = getWindow().getDecorView();
        //Activity's root View. Can also be root View of your layout
        final View rootView = decorView.findViewById(android.R.id.content);
        //set background, if your root layout doesn't have one
        final Drawable windowBackground = decorView.getBackground();

        mBurView.setupWith((ViewGroup) rootView)
                .windowBackground(windowBackground)
                .blurAlgorithm(new SupportRenderScriptBlur(
                        this)) //Optional, enabled by default. User can have custom
                // implementation
                .blurRadius(8f);

        mBurView.setBlurAutoUpdate(true);
    }
}
